﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.guide.actions {
    import Engine.Transactions.*;
    import flash.utils.*;
    import Classes.util.*;

    public class GAWaitForTransaction extends GuideAction implements ITransactionManagerListener {

        protected var m_predicate:Function = null;
        protected var m_requiredSuccessCount:int = 1;
        protected var m_runningSuccessCount:int = 0;

        protected static function makeClassTestFn(_arg1:String):Function{
            var className:* = _arg1;
            return (function (_arg1:Transaction):Boolean{
                var _local2:* = getQualifiedClassName(_arg1);
                return ((_local2 == className));
            });
        }

        public function beforeTransactionAdded(_arg1:Transaction, _arg2:Boolean):void{
        }
        public function afterTransactionAdded(_arg1:Transaction, _arg2:Boolean):void{
            if (this.m_predicate(_arg1)){
                this.m_runningSuccessCount++;
            };
            if (this.m_runningSuccessCount >= this.m_requiredSuccessCount){
                removeState(this);
            };
        }
        override public function createFromXml(_arg1:XML):Boolean{
            var _local2:XMLList = checkAndGetElement(_arg1, "transaction");
            if (!_local2){
                return (false);
            };
            var _local3:String = String(_local2.@className);
            var _local4:int = int(_local2.@count);
            this.m_predicate = makeClassTestFn(_local3);
            if (_local4 > 0){
                this.m_requiredSuccessCount = _local4;
            };
            return (true);
        }
        override public function enter():void{
            super.enter();
            GameTransactionManager.addListener(this);
        }
        override public function reenter():void{
            GameTransactionManager.addListener(this);
        }
        override public function exit():void{
            GameTransactionManager.removeListener(this);
        }
        override public function removed():void{
            GameTransactionManager.removeListener(this);
        }

    }
}//package Modules.guide.actions 
